package chapter04.Demo1;

/**
 * 1.继承
 * 2.重写
 */
class Flower{//花朵类
    String color;//花瓣颜色
    int petalNumber;//花瓣数量
    String petalType;//花瓣类型
    String FlowerTime;//花期
    public void setFlowerTime(String FlowerTime){
        this.FlowerTime = FlowerTime;
    }
    public  String getFlowerTime(){
        return FlowerTime;
    }
    public void setColor (String color) {
        this.color = color;//设置花瓣颜色
    }
    public String getColor(){
        return color;
    }
     }
     //牡丹类继承了花朵类
     class penoy extends Flower{
         public void FlowerLanguage() {
             System.out.println("一朵牡丹，一场人间富贵！");
         }
         public void setFlowerTime(String flowerTime){//重写
             if (this.color.equals("黄色")){//黄色的花都是5月
                 this.FlowerTime = "5月";
             }else {
                 this.FlowerTime = flowerTime;//用户输入的花期
             }
         }
         public String getFlowerTime(){
             return FlowerTime;
         }
     }
public class demo1 {
    public static void main(String[] args) {
        penoy penoy = new penoy();
        penoy.setColor("黄色");
        penoy.setFlowerTime("3月-4月");
        System.out.println("黄色牡丹花期"+penoy.getFlowerTime());
        penoy.petalNumber = 1000;
        penoy.petalType = "重瓣型";
        System.out.println("牡丹花颜色"+ penoy.getColor());
        penoy.FlowerLanguage();
    }
}
